<template>
  <el-table :data="dataList" border fit highlight-current-row @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55">
    </el-table-column>
    <el-table-column v-for="(item) in engTh" :key="item" :label="formTh[`${item}`]">
      <template v-slot="scope">
        {{ handleItem(item, scope.row[`${item}`]) }}
      </template>
    </el-table-column>
    <el-table-column fixed="right" label="操作" width="150">
      <template v-slot="scope">
        <el-button type="success" size="small" @click="showJournalList2(scope.row.transactionId)">查看分录信息</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>



<script lang="ts" setup>
import { CostTransactionProcess } from "@/requests/request";
import { exportExcel, filterExcelContentArr } from "@/utils/excel";
import { journalTableHeader, purTableHeader, purTableProps } from "./data";
import { onMounted } from "vue";
import { cmsToFloat } from "@/utils/number";

const props = defineProps({
  dataList: Array<CostTransactionProcess>,
  engTh: Array<String | null>
});
const formTh = Object.assign(purTableHeader, journalTableHeader)
const emit = defineEmits(['showJournalList'])
const showJournalList2 = (businessId: string) => {
  emit('showJournalList', businessId);
}
onMounted(() => {
  console.log('数据123', formTh, props.dataList)
})

let selectedArr: Array<any> = []
const handleSelectionChange = (val: Array<any>) => {
  console.log('选择的值', val);
  selectedArr = val;
}
const exportItems = () => {
  const sheetArr = filterExcelContentArr(selectedArr, purTableProps, purTableHeader)
  console.log('过滤的值', sheetArr)
  exportExcel("事务处理明细.xlsx", sheetArr)

}
// 暴露出去被引用
defineExpose({
  exportItems
})
enum accountingTypeEnum {
  "入库检验" = 1,
  "库存估价" = 2,
  "采购价格差异或汇率差异" = 3,
}
const handleItem = (key: any, value: any) => {
  if (key === 'accountingType') {
    return accountingTypeEnum[value]
  } if (key === 'unitCost') {
    return cmsToFloat(value, 8)
  } else {
    return value
  }
}
</script>
